#ifndef SERIALBUFFER_H
#define SERIALBUFFER_H

#include "serialport.h"

class __EXPORT SerialBuffer : public SerialPort {
public:
	SerialBuffer(void *buf, int size) : buf_(buf), size_(size) {}
	virtual ~SerialBuffer() {}
	
	virtual bool lock() {return true;}
	virtual void unlock() {}
	
	virtual int read(void *buf, int size) {
		if (size > size_)
			size = size_;

		memcpy(buf, buf_, size);
		buf_ = (char *)buf_ + size;
		size_ -= size;
		return size;
	}

	virtual void write(const void *buf, int size) {}
	virtual void clean() {}

private:
	SerialBuffer();

	void *buf_;
	int size_;
};


#endif
